package com.hzdl.car.controller;

import com.github.pagehelper.PageInfo;
import com.hzdl.car.service.CheckService;
import com.hzdl.car.util.AJAXResult;
import com.hzdl.car.vo.CarReturnVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/check")
public class CheckController {
    @Autowired
    private CheckService cs;

    @RequestMapping("/checkInfoInit")
    public String checkInfoInit(){
        return "/system/check";
    }

    @RequestMapping("/checkInfoShow")
    @ResponseBody
    public AJAXResult checkInfoShow(CarReturnVo carReturnVo){
        if(carReturnVo.getPage()==null){
            carReturnVo.setPage(1);
        }
        if(carReturnVo.getLimit()==null){
            carReturnVo.setLimit(5);
        }
        PageInfo pageInfo=cs.findByWhere(carReturnVo);
        return new AJAXResult(0,"",pageInfo.getList(),pageInfo.getTotal());
    }
    @RequestMapping("/checkUpdate")
    @ResponseBody
    public AJAXResult checkUpdate(CarReturnVo carReturnVo){
        int row=cs.updateCheck(carReturnVo);
        if(row==0){
            return AJAXResult.UPDATE_ERROR;
        }
        return AJAXResult.UPDATE_SUCCESS;
    }

    @RequestMapping("/checkDelete")
    @ResponseBody
    public AJAXResult checkDelete(String checkid){
        int row=cs.deleteCheck(checkid);
        if(row==0){
            return AJAXResult.DELETE_ERROR;
        }
        return AJAXResult.DELETE_SUCCESS;
    }


}
